package controller;

import implementor.CategoryImp;

import implementor.MaterialImp;
import implementor.ModelImp;
import implementor.PurchaseImp;
import implementor.SellerInfoImp;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.sql.Date;

import javax.swing.table.DefaultTableModel;
import javax.swing.text.Utilities;

import daoInterface.CategoryDao;

import daoInterface.MaterialDao;
import daoInterface.ModelDao;
import daoInterface.PurchaseDao;
import daoInterface.SellerInfoDao;

import dto.Category;
import dto.Material;
import dto.Purchase;
import dto.Sell;
import dto.SellerInfo;

import model.Stock;


import utilities.AppUtilites;
import utilities.ViewUtilites;
import views.inventory.StockReport;

public class StockReportController implements ActionListener
{
	private StockReport view;
	private Stock model;
	

	public StockReportController() {
		
	}
	
	public StockReportController(StockReport view, Stock model) {
		super();
		this.view = view;
		this.model = model;
		view.actionlisteners(this);
		
		AppUtilites.setCategoryCombo(view.getLevel3Combo());
		AppUtilites.setSellerNameCombo(view.getSellerNameCombo());
		AppUtilites.setSizeCombo(view.getSizeCombo());
	}

	public StockReport getView() {
		return view;
	}

	public void setView(StockReport view) {
		this.view = view;
	}

	public Stock getModel() {
		return model;
	}

	public void setModel(Stock model) {
		this.model = model;
	}

	
	
	
	
	public void reactToGenerate()
	
	{
		
		String catname=view.getLevel3Combo().getSelectedItem().toString();
		String sellerName=view.getSellerNameCombo().getSelectedItem().toString();
		String size=view.getSizeCombo().getSelectedItem().toString();
		
		ModelDao models=new ModelImp();
		Stock[] stocks=models.retreiveStockReport(catname, size, sellerName);
		
		
		DefaultTableModel dm=(DefaultTableModel) view.getTable().getModel();
		for(int i=0;i<stocks.length;i++)
			dm.addRow(new Object[]{stocks[i].getSellerName(),stocks[i].getMatmodel().getCatId(),stocks[i].getMatmodel().getSizeName(),stocks[i].getPurchaseQuant(),
					stocks[i].getMatmodel().getmQuant()});
		
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		String k=arg0.getActionCommand();
		
		if(k.contains("GENERATE"))
		{
	
			reactToGenerate();
		}
	
	}
	
		
		
		
		
		
	}
	


